/* TODO: Have to improve queue api performance */

#ifndef __QUEUE_H
#define __QUEUE_H

#include <stdio.h>
#include <stdlib.h>


#ifdef WIN32
#include <windows.h>
#else
#include <unistd.h>
#include <pthread.h>
#include <semaphore.h>
#endif

#ifdef __BUILD_DICOM__
#include "list.h"
#else
#include <dicom/list.h>
#endif

typedef struct {
    struct list_head list;
#ifdef WIN32
    HANDLE mutex;
    HANDLE not_empty;
#else
    pthread_mutex_t mutex;
    sem_t *not_empty;
#endif
    int count;
} queue_t;

struct __data {
    struct list_head list_node;
    void *data;
};



queue_t *queue_create(void);

int queue_push(queue_t *queue, void *data);

void *queue_pop(queue_t *queue);

void *queue_pop_wait(queue_t *queue);

int queue_is_empty(queue_t *queue);

inline int queue_count(queue_t *queue);

void *queue_peek_head(queue_t *queue);

void *queue_peek_tail(queue_t *queue);

void *queue_peek_nth(queue_t *queue, int nth);

int queue_index(queue_t *queue, void *data);

void *queue_steal_nth(queue_t *queue, int nth);

void *queue_steal(queue_t *queue, void *data);

void *queue_steal_wait(queue_t *queue, void *data);

void queue_destroy(queue_t *queue);

#endif

